#
#   exceptions.py
#   journalismManger
#
#   Created by luoxh on 2019-07-19-16:39.
#   Copyright © 2019 luoxh. All rights reserved.
#
import json

from flask import request, current_app
from flask_api.exceptions import APIException


class CustomException(APIException):

    def __init__(self, data, detail=None):
        super().__init__(detail)
        self.request = request.method + ' ' + current_app.get_url_no_param()
        if isinstance(data, str):
            self.code = 10000  # debug下的输出
            self.msg = data
        self.code = data.value
        self.msg = data.description

    def __str__(self):
        return json.dumps(self.__dict__)
